package com.biyao.es.controller;

import com.biyao.es.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * es增删改查
 *
 * @author: hxs
 * @create: 2020/7/7
 */
@RestController
@RequestMapping("/api")
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 功能描述 elasticsearch添加数据
     *
     * @param keyword 快捷键
     * @return java.lang.Boolean
     * @author hxs
     * @date 2020/7/7
     */
    @PutMapping("/es/{keyword}")
    public Boolean parse(@PathVariable("keyword") String keyword) throws Exception {
        return contentService.addContent(keyword);
    }

    /**
     * 功能描述 elasticsearch分页查询
     *
     * @param keyword  关键字
     * @param pageNo   页码
     * @param pageSize 页大小
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author hxs
     * @date 2020/7/7
     */
    @GetMapping("es/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize) throws Exception {
        return contentService.findByPage(keyword, pageNo, pageSize);
    }

    /**
     * 功能描述 elasticsearch高亮分页查询
     *
     * @param keyword  关键字
     * @param pageNo   页码
     * @param pageSize 页大小
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author hxs
     * @date 2020/7/7
     */
    @GetMapping("es/search-hight/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> searchByHight(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize) throws Exception {
        return contentService.findHignLightByPage(keyword, pageNo, pageSize);
    }
} 